function Sigma = scgibbshelperinv(dets, suminv, newk)
if newk == 1
    Sigma = shiftdim(suminv(:,1)',-1);
    return;
end
inva = dets(:,newk-1)./dets(:,newk);
if newk == 2
    invb = -inva+0.5*dets(:,2).*suminv(:,2)./dets(:,newk);
else
    invb = -inva+0.5*dets(:,2).*suminv(:,2).*dets(:,newk-2)./dets(:,newk);
end
Sigma = repmat(shiftdim(invb',-1), [newk, newk, 1]);
for kk = 0:newk-1
    Sigma(kk*(newk+1)+1:newk*newk:end) = inva';
end

end